<?php
namespace Amis\form;
class InputRange extends FormItem
{
    public string $type = 'input-range';

    public function min(int $min = 0)
    {
        $this->min = $min;
        return $this;
    }

    public function max(int $max = 100)
    {
        $this->max = $max;
        return $this;
    }

    public function disabled(bool $disabled = false)
    {
        $this->disabled = $disabled;
        return $this;
    }

    public function step(int $step = 1)
    {
        $this->step = $step;
        return $this;
    }

    public function showSteps(bool $showSteps = false)
    {
        $this->showSteps = $showSteps;
        return $this;
    }

    /**
     * 分割的块数
     * 主持数组传入分块的节点
     * @param int $parts
     * @return $this
     */
    public function parts(int $parts = 1)
    {
        $this->parts = $parts;
        return $this;
    }

    /**
     * 刻度标记
     * - 支持自定义样式
     * - 设置百分比
     * { [number | string]: ReactNode } or { [number | string]: { style: CSSProperties, label: ReactNode } }
     * @param $marks
     * @return $this
     */
    public function marks($marks)
    {
        $this->marks = $marks;
        return $this;
    }

    /**
     * 是否显示滑块标签
     * @param bool $tooltipVisible
     * @return $this
     */
    public function tooltipVisible(bool $tooltipVisible = false)
    {
        $this->tooltipVisible = $tooltipVisible;
        return $this;
    }

    /**
     * 滑块标签的位置，默认auto，方向自适应
     * 前置条件：tooltipVisible 不为 false 时有效
     * @param string $tooltipPlacement
     * @return $this
     */
    public function tooltipPlacement(string $tooltipPlacement = 'top')
    {
        if (in_array($tooltipPlacement, ['auto', 'top', 'bottom', 'right']))
            $this->tooltipPlacement = $tooltipPlacement;
        return $this;
    }

    /**
     *    控制滑块标签显隐函数 直接写字符串 js function 函数
     * 前置条件：tooltipVisible 不为 false 时有效
     * @param string $tooltipPlacement
     * @return $this
     */
    public function tipFormatter(string $tooltipPlacement = '')
    {
        $this->tipFormatter = $tooltipPlacement;
        return $this;
    }

    /**
     * @param bool $multiple
     * @return $this
     */
    public function multiple(bool $multiple = false)
    {
        $this->multiple = $multiple;
        return $this;
    }

    /**
     * 默认为 true，选择的 value 会通过 delimiter 连接起来，否则直接将以{min: 1, max: 100}的形式提交
     * 前置条件：开启multiple时有效
     * @param bool $joinValues
     * @return $this
     */
    public function joinValues(bool $joinValues = true)
    {
        $this->joinValues = $joinValues;
        return $this;
    }

    public function delimiter($delimiter = false)
    {
        $this->delimiter = $delimiter;
        return $this;
    }

    public function unit(string $unit)
    {
        $this->unit = $unit;
        return $this;
    }

    public function clearable(bool $clearable = false)
    {
        $this->clearable = $clearable;
        return $this;
    }

    public function showInput(bool $showInput = false)
    {
        $this->showInput = $showInput;
        return $this;
    }

    /**
     * 当 组件 的值发生改变时，会触发 onChange 事件，并把改变后的值作为参数传入
     * @param string $onChange
     * @return $this
     */
    public function onChange(string $onChange)
    {
        $this->onChange = $onChange;
        return $this;
    }

    /**
     * 与 onmouseup 触发时机一致，把当前值作为参数传入
     * @param string $onAfterChange
     * @return $this
     */
    public function onAfterChange(string $onAfterChange)
    {
        $this->onAfterChange = $onAfterChange;
        return $this;
    }
}